//
//  MagazineDataViewController.m
//  B_WatchHome
//
//  Created by dllo on 15/12/23.
//  Copyright © 2015年 DHF. All rights reserved.
//

#import "MagazineDataViewController.h"
#import <MBProgressHUD.h>


@interface MagazineDataViewController ()<UIWebViewDelegate>

@end

@implementation MagazineDataViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    NSString *str = self.model.link_share;
//    NSLog(@"@@@@@@@@@@@@@%@", self.model.link_share);
    
    // 关闭导航栏半透明
    self.navigationController.navigationBar.translucent = NO;
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStyleDone target:self action:@selector(leftButtonAction:)];
    self.navigationItem.title = @"IDailyMagazine";
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    // 创建WebView
    UIWebView *myWebView = [[UIWebView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    
    myWebView.backgroundColor = [UIColor whiteColor];
    
    myWebView.delegate = self;
    
    NSURL *url = [NSURL URLWithString:str];
    
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    
    [myWebView loadRequest:request];
    
    // 取消边界反弹
    myWebView.scrollView.bounces = NO;
    
    [self.view addSubview:myWebView];
    
    // 右上角双按钮
    UIView *rightBarView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 60, 35)];
    // 收藏按钮
    UIButton *collectButton = [UIButton buttonWithType:UIButtonTypeCustom];
    collectButton.frame = CGRectMake(0, 0, 30, 30);
    [collectButton setImage:[UIImage imageNamed:@"msc.png"] forState:UIControlStateNormal];
    [collectButton addTarget:self action:@selector(collectAction:) forControlEvents:UIControlEventTouchDown];
    [rightBarView addSubview:collectButton];
    
    // 分享按钮
    UIButton *shareButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [shareButton setFrame:CGRectMake(35, 0, 30, 30)];
    [shareButton setImage:[UIImage imageNamed:@"fx.png"] forState:UIControlStateNormal];
    [shareButton addTarget:self action:@selector(shareAction:) forControlEvents:UIControlEventTouchDown];
    [rightBarView addSubview:shareButton];
    rightBarView.backgroundColor = [UIColor clearColor];
    
    UIBarButtonItem *rightBtn = [[UIBarButtonItem alloc] initWithCustomView:rightBarView];
    self.navigationItem.rightBarButtonItem = rightBtn;
    
    self.isSelected = YES;
    
    
}

// 收藏按钮点击触发
- (void)collectAction:(UIButton *)btn
{
    NSLog(@"收藏");
    
    if (self.isSelected == NO) {
        [btn setBackgroundImage:[UIImage imageNamed:@"msc.png"] forState:UIControlStateNormal];
    }else{
        [btn setBackgroundImage:[UIImage imageNamed:@"sc.png"] forState:UIControlStateNormal];
    }
    self.isSelected = !self.isSelected;
    
}

// 分享按钮
- (void)shareAction:(UIButton *)btnShare
{
    NSLog(@"二哥太帅了");
   
}


// 返回上一页
- (void)leftButtonAction:(UIBarButtonItem *)btn
{
    [self.navigationController popViewControllerAnimated:YES];
}

// 网页开始加载时调用
- (void)webViewDidStartLoad:(UIWebView *)webView
{
    // 开始菊花
    [self MBProgressHUDStart];
}

// 网页加载完成时调用
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    // 停止菊花
    [self MBProgressHUDStop];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
